1917A - Least Product - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#pragma GCC target("popcnt")
#define endl '\n'
#define F first
#define S second
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Ok(x) x == true ?cout<<"Yes"<<endl : cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int N = 1e6+30;
const int M = 1e9 + 7;
const int LOG = 27;
const ll INF = 1e18;
///////////////////////////////////////////////////////////////////
struct tt
{
    int F, S, T;
    tt() {}
    tt(int a,int b, int c)
    {
        F = a;
        S = b;
        T = c;
    }
    bool operator < (const tt & n) const
    {
        if( F == n.F )
        {
            return S > n.S;
        }
        return F < n.F;
    }

};
ll poww(ll x, ll n, ll mod = INF)
{
    if(x == 0) return 0 ;
    if(x == 1) return 1;
    if(n == 0) return 1 ;
    if(n == 1) return x%mod ;
    ll Ans = poww(x, n/2, mod)%mod ;
    Ans = (Ans * Ans)%mod;
    if(n%2) return (Ans *x) %mod ;
    return Ans ;
}
ll inv(ll x,ll mod)
{
    return poww(x, mod-2, mod)%mod ;
}
ll Gcd(ll x,ll y)
{
    return y ? Gcd(y,x%y) : x ;
}
ll fact[N];
void fac()
{
    fact[0]  =  1;
    for( ll i = 1 ; i < N ; i++ )
    {
        fact[i] = (fact[i-1]*i)%M;
    }
    return;
}
ll C(ll a, ll b)
{
    if(a-b<0)return 0LL;
    ll res = (fact[a]*inv(fact[b],M))%M;
    res = res*inv(fact[a-b],M)%M;
    return res;
}
int viss[2*N];
void seive()
{
    viss[1] = 0 ;
    viss[0] = 1;
    for( int i = 2 ; i < N ; i++ )
    {
        if(!viss[i])
        {
            for( int j = i ; j < N ; j += i  )
            {
                if(viss[j] == 0)
                    viss[j] = i;
            }
        }
    }
}
string toBinary(int x)
{
    string ret;
    while(x)
    {
        ret = ret +  char((x % 2) + '0');
        x /= 2;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}
ll segma( ll x, ll y )
{
    ll res = ( y - x + 1 );
    res = res * ( x + y );
    res /= 2;
    return res;
}
int count(const string& s, const string& T)
{
    int cnt = 0;
    for (int i = 0; i < (int)s.size(); ++i)
    {
        if (s.substr(i, T.size()) == T)
        {
            ++cnt;
        }
    }
    return cnt;
}
ll maxSubArraySum(ll a[], int size)
{
    ll max_so_far = -INF, max_ending_here = 0, start = 0, end = 0, s = 0;
    for(int i = 1; i <= size; i++)
    {

        if( abs(a[i]%2) != abs(a[i-1]%2) )
        {
            max_ending_here = 0;
        }
        max_ending_here += a[i];
        if(max_so_far < max_ending_here)
        {
            max_so_far = max_ending_here;
        }
        if(max_ending_here < 0)
        {
            max_ending_here = 0;
        }
    }
    return  max_so_far;
}
template<typename S, typename T> S smax(S& a, const T& b)
{
    if(a < b) a = b;
    return a;
}
template<typename S, typename T> S smin(S& a, const T& b)
{
    if(a > b) a = b;
    return a;
}
int di[4] = { -1, 1, 0, 0 };
int dj[4] = { 0, 0, 1, -1 };
///////////////////////////////////////////////////////////////////
void Solve()
{
    int n;
    cin >> n;
    bool ok = false;
    int x = 0 ;
    vector < int > arr ( n + 1 , 0 );
    for ( int i = 1 ; i <= n ; i++ ){
        cin >> arr[i];
        if ( arr[i] == 0 ){
            ok = 1;
        }
        if ( arr[i] < 0 ){
            x++;
        }
    }
    if ( x % 2 ){
        cout << 0 << endl;
        return;
    }
    if ( ok ){
        cout << 0 << endl;
        return ;
    }
    cout << 1 << endl << 1 << ' ' << 0 << endl;
}
int main()
{
    Fast;
    /*freopen("input.txt","r" ,stdin );
    freopen("output.txt","w" ,stdout);*/
    int Test = 1 ;
    seive();
    cin >> Test;
Start:
    for(int test = 1 ; test <= Test ; test++ )
    {
        Solve();
    }
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

6. Zigzag Conversion
1612B - Special Permutation
1481. Least Number of Unique Integers after K Removals
1035. Uncrossed Lines
328. Odd Even Linked List
1219. Path with Maximum Gold
1268. Search Suggestions System
841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III
869. Reordered Power of 2
1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram